package com.huacai.restaurant.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.huacai.common.annotation.Log;
import com.huacai.common.core.controller.BaseController;
import com.huacai.common.core.domain.AjaxResult;
import com.huacai.common.enums.BusinessType;
import java.io.InputStream;
import org.springframework.web.multipart.MultipartFile;
import com.huacai.restaurant.domain.Restaurant;
import com.huacai.restaurant.service.IRestaurantService;
import com.huacai.common.utils.poi.ExcelUtil;
import com.huacai.common.core.page.TableDataInfo;

/**
 * 餐厅信息Controller
 *
 * @author laq
 * @date 2025-06-17
 */
@RestController
@RequestMapping("/huacai/restaurant")
public class RestaurantController extends BaseController
{
    @Autowired
    private IRestaurantService restaurantService;

    /**
     * 查询餐厅信息列表
     */
    @PreAuthorize("@ss.hasPermi('huacai:restaurant:list')")
    @GetMapping("/list")
    public TableDataInfo list(Restaurant restaurant)
    {
        startPage();
        List<Restaurant> list = restaurantService.selectRestaurantList(restaurant);
        return getDataTable(list);
    }

    /**
     * 导出餐厅信息列表
     */
    @PreAuthorize("@ss.hasPermi('huacai:restaurant:export')")
    @Log(title = "餐厅信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Restaurant restaurant)
    {
        List<Restaurant> list = restaurantService.selectRestaurantList(restaurant);
        ExcelUtil<Restaurant> util = new ExcelUtil<Restaurant>(Restaurant.class);
        util.exportExcel(response, list, "餐厅信息数据");
    }

    /**
     * 下载模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<Restaurant> util = new ExcelUtil<Restaurant>(Restaurant.class);
        util.importTemplateExcel(response, "餐厅信息数据");
    }

    /**
     * 导入数据
     */
    @Log(title = "餐厅信息", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('huacai:restaurant:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception
    {
        ExcelUtil<Restaurant> util = new ExcelUtil<Restaurant>(Restaurant.class);
        InputStream inputStream = file.getInputStream();
        List<Restaurant> list = util.importExcel(inputStream );
        inputStream.close();
        int count = restaurantService.batchInsertRestaurant(list);
        return AjaxResult.success("导入成功" + count + "条信息！");
    }

    /**
     * 获取餐厅信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('huacai:restaurant:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(restaurantService.selectRestaurantById(id));
    }

    /**
     * 新增餐厅信息
     */
    @PreAuthorize("@ss.hasPermi('huacai:restaurant:add')")
    @Log(title = "餐厅信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Restaurant restaurant)
    {
        return toAjax(restaurantService.insertRestaurant(restaurant));
    }

    /**
     * 修改餐厅信息
     */
    @PreAuthorize("@ss.hasPermi('huacai:restaurant:edit')")
    @Log(title = "餐厅信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Restaurant restaurant)
    {
        return toAjax(restaurantService.updateRestaurant(restaurant));
    }

    /**
     * 删除餐厅信息
     */
    @PreAuthorize("@ss.hasPermi('huacai:restaurant:remove')")
    @Log(title = "餐厅信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(restaurantService.deleteRestaurantByIds(ids));
    }

    /**
     * 不分页查询餐厅列表
     */
    @GetMapping("/selectRestaurantsByList")
    public AjaxResult selectRestaurantsByList() {
        // 创建一个空的查询对象，获取所有餐厅
        Restaurant restaurant = new Restaurant();
        List<Restaurant> list = restaurantService.selectRestaurantAllList(restaurant);
        return success(list);
    }
}
